package com.kfm.hotel.controller;

import com.kfm.hotel.domain.SysMenu;
import com.kfm.hotel.domain.SysUser;
import com.kfm.hotel.service.SysMenuService;
import com.kfm.hotel.util.Constant;
import com.kfm.hotel.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/sysmenu")
public class SysMenuController {

    @Autowired
    private SysMenuService service;


    @GetMapping("/init")
    public R init(@SessionAttribute(Constant.LOGIN_USER)SysUser user){
        // 根据用户查询对应的菜单
        return R.ok("success", service.getTreeMenuWithHutool(user.getId()));
    }

    @GetMapping("/list")
    public R  list() {
        return R.ok("success");
    }


    @GetMapping("/grant/{roleId}")
    public ModelAndView grant(@PathVariable("roleId") Integer roleId){
        ModelAndView modelAndView = new ModelAndView("sysrole/grant");
        modelAndView.addObject("roleId", roleId);
        return modelAndView;
    }

    @GetMapping("/getMenu/{roleId}")
    public R getMenu(@PathVariable("roleId") Integer roleId){
        return R.ok(service.grantTreeMenu());
    }

    @GetMapping("/extracted/{roleId}")
    public R grantMenu(@PathVariable("roleId") Integer roleId){
        return R.ok(service.extracted(roleId));
    }



}
